﻿Public Class FrmLauncher
    Private Sub FrmLauncherLoad (sender As Object, e As EventArgs) Handles MyBase.Load
        Icon = Icon.FromHandle (My.Resources.H200.GetHicon())
        _btnAceptar.Enabled = False
        Text = Título
    End Sub

    Private Sub BtnAceptarClick (sender As Object, e As EventArgs) Handles btnAceptar.Click
        DialogResult = DialogResult.OK
        Close()
    End Sub

    Private Sub BtnCancelarClick (sender As Object, e As EventArgs) Handles btnCancelar.Click
        DialogResult = DialogResult.Cancel
        Close()
    End Sub

    Private Sub FrmLauncherFormClosing (sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
        If Not SigueHaciendoPing Then
            Timer1.Stop()
        End If
        If DialogResult <> DialogResult.OK Then
            P2PEncapsulado.Dispose()
            Application.Exit()
        End If
    End Sub

    Private Sub Timer1Tick (sender As Object, e As EventArgs) Handles Timer1.Tick
        P2PEncapsulado.Send (NúmeroTicketTurno.ToString ("000"))
        For Each h As HostHelper In P2PEncapsulado.HostList
            If Not ListBox1.Items.Contains (cadenaListBox (h)) Then
#If Not Debug Then
                If h.IsSearchingForEnemy And Not h = P2PEncapsulado.HostPropio Then
#End If
                ListBox1.Items.Add (cadenaListBox (h))
#If Not Debug Then
                End If
#End If
            Else
                If Not h.IsSearchingForEnemy Then
                    ListBox1.Items.Remove (cadenaListBox (h))
                End If
            End If
        Next
        _btnAceptar.Enabled = _ListBox1.Items.Count > 0
    End Sub

    Private Shared Function CadenaListBox (ByVal h As HostHelper) As String
#If DEBUG Then
        Return h.UserName + " (" + h.BoletoLoteriaTurno.ToString("000") + ")"
#Else
        Return h.UserName
#End If
    End Function

    Private Sub FrmLauncherKeyPress (sender As Object, e As KeyPressEventArgs) Handles Me.KeyPress
        'btnAceptar.Enabled = e.KeyChar = "º"c
    End Sub
End Class